import {
  ConfigProvider,
  Button,
  Input,
  Layout,
  message,
  notification,
  Modal,
  Tooltip,
  Popover,
  Select,
  Menu,
  Checkbox,
  Cascader,
  Divider,
  Card,
  Form,
  InputNumber,
  Radio,
  Upload,
  // Table,
  Drawer,
  Switch,
  Tree,
  Row,
  Col,
  Badge,
  PageHeader,
  Dropdown,
  Avatar,
  Tag,
  List,
  Descriptions,
  Spin,
  Popconfirm,
  Tabs,
  AutoComplete,
  Collapse,
  Space,
  Alert,
  Empty,
  Statistic,
  Progress,
  Image,
  TreeSelect,
  Pagination,
  Steps,
  Anchor,
  Breadcrumb,
  Timeline,
  DatePicker,
  TimePicker,
  Calendar,
} from "ant-design-vue";
import i18n from "../../locale";
import store from "@/store/index";
import request from "./request";
import utils from "./utils";
import defaultSetting from "./defaultSetting";
import { mainAppRouter } from "../../router/index";
import CuIcon from "./icon";
import BLCOMMON from "bl-common-vue3";
import ATable from "@/components/Table/index.vue";

const appUse = (app) => {
  let tableConfig = store.getters.tableConfig;
  if (tableConfig.isZebra) {
    document.documentElement.style.setProperty(
      "--zebraColor",
      tableConfig.zebraColor
    );
  }
  document.documentElement.style.setProperty(
    "--tableContentSize",
    tableConfig.tableContentSize
  );
  document.documentElement.style.setProperty(
    "--tableTitleSize",
    tableConfig.tableTitleSize
  );
  document.documentElement.style.setProperty(
    "--tableHeaderSize",
    tableConfig.tableHeaderSize
  );
  // 路由导航
  app.use(mainAppRouter);
  // 全局多语言
  app.use(i18n);
  // vuex
  app.use(store);
  // 使用自定义图标库
  app.component("CuIcon", CuIcon);
  // 全局引入部分常用antd 组件
  app.use(ConfigProvider);
  app.use(Button);
  app.use(Input);
  app.use(Layout);
  app.use(Tooltip);
  app.use(Popover);
  app.use(Select);
  app.use(Menu);
  app.use(Modal);
  app.use(Checkbox);
  app.use(Cascader);
  app.use(Divider);
  app.use(Card);
  app.use(Form);
  app.use(InputNumber);
  app.use(Radio);
  app.use(Upload);
  app.component('a-table', ATable);// 覆盖组件
  app.use(Drawer);
  app.use(Switch);
  app.use(Tree);
  app.use(Row);
  app.use(Col);
  app.use(Badge);
  app.use(PageHeader);
  app.use(Dropdown);
  app.use(Avatar);
  app.use(Tag);
  app.use(List);
  app.use(Descriptions);
  app.use(DatePicker);
  app.use(Spin);
  app.use(Popconfirm);
  app.use(Tabs);
  app.use(AutoComplete);
  app.use(Collapse);
  app.use(Space);
  app.use(Alert);
  app.use(Empty);
  app.use(Statistic);
  app.use(Progress);
  app.use(Image);
  app.use(TreeSelect);
  app.use(Pagination);
  app.use(Steps);
  app.use(Anchor);
  app.use(Breadcrumb);
  app.use(Timeline);
  app.use(TimePicker);
  app.use(Calendar);

  // 全局挂载提示、通知和确认弹窗 请求方法等
  app.config.globalProperties.$message = message;
  app.config.globalProperties.$notification = notification;
  app.config.globalProperties.$confirm = Modal.confirm;
  app.config.globalProperties.$info = Modal.info;
  app.config.globalProperties.$success = Modal.success;
  app.config.globalProperties.$error = Modal.error;
  app.config.globalProperties.$warning = Modal.warning;
  app.config.globalProperties.$request = request;
  app.config.globalProperties.$post = request.post;
  app.config.globalProperties.$get = request.get;
  app.config.globalProperties.$utils = utils;
  app.config.globalProperties.$settings = defaultSetting;
  app.config.globalProperties.$store = store;
  app.config.globalProperties.$L = BLCOMMON.utils.L;

  // 按钮权限控制
  // 1 显隐控制
  app.directive("permission", {
    beforeMount(el, binding) {
      if (!BLCOMMON.utils.getBtnPermission(binding.value)) {
        el.style.display = "none";
      }
    },
  });
  // 2是否可点击控制
  app.directive("action", {
    mounted(el, binding) {
      if (!BLCOMMON.utils.getBtnPermission(binding.value)) {
        el.disabled = true;
        el.title = "您没有权限操作";
      }
    },
  });
};

export default appUse;
